package org.timemanager.view;

import java.util.Calendar;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

/**
 * list daily events
 * @author Dereky
 *
 */
public class DailyAnalyzeActivity extends Activity {
	public static Calendar curCalendar;
	private TextView dailyAnalyze;
	/**
	 * the panel to draw static chart.
	 */
	private DailyAnalyzeView dailyCanvas;
	/**
	 * true means drawing bar statistics chart,
	 * false means drawing pie statistics chart.
	 */
	public static boolean isShowBarView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		curCalendar=Calendar.getInstance();
		curCalendar.set(Calendar.SECOND, 0);
		curCalendar.set(Calendar.MILLISECOND, 0);
		setContentView(R.layout.daily_analyze);
		initAllConfiguration();
	}
	/**
	 * initialize all parameters
	 */
	private void initAllConfiguration(){
		
		findViewById(R.id.daily_return).setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				finish();
			}
		});
		dailyAnalyze= (TextView) findViewById(R.id.daily_analyze);
		dailyCanvas=(DailyAnalyzeView) findViewById(R.id.daily_canvas);
		
		isShowBarView=true;
		dailyAnalyze.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				isShowBarView=!isShowBarView;
				showStatisticView();
			}
		});
	}
	@Override
	protected void onStart() {
		super.onStart();
		showStatisticView();
	}
	@Override
	protected void onDestroy() {
		super.onDestroy();
		dailyCanvas.close();
	}
	private void showStatisticView(){
		if(isShowBarView){
			dailyCanvas.showBarView();
			dailyAnalyze.setText(getText(R.string.daily_analyze_pie));
			
		}
		else{
			dailyCanvas.showPieView();
			dailyAnalyze.setText(getText(R.string.daily_analyze_bar));
		}
	}
}
